package com.ushine.web.template.desensitization.model;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.ushine.web.base.model.base.BaseBO;
import com.ushine.web.component.mybatis.decryption.AesTypeHandler;
import com.ushine.web.component.mybatis.desensitization.SensitiveTypeEnum;
import com.ushine.web.component.mybatis.desensitization.annotation.Desensitization;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import java.io.Serializable;

/**
 * @Author: yls
 * @Date 2022/2/10 16:46
 * @Description: 字段脱敏
 *                 autoResultMap = true 涉及加密/解密字段必须添加该属性，否则无法解密
 * @Version 1.0
 **/
@EqualsAndHashCode(callSuper = true)
@Data
@Entity
@ApiModel(description = "字段脱敏表")
@Table(name = "t_cp_field_desensitization")
@org.hibernate.annotations.Table(appliesTo = "t_cp_field_desensitization", comment = "字段脱敏")
@TableName(value = "t_cp_field_desensitization", autoResultMap = true)
public class FieldDesensitizationDO extends BaseBO implements Serializable {
    /**
     * 编号
     * 解决前台js接收雪花id精度丢失问题：@JsonFormat(shape = JsonFormat.Shape.STRING)
     */
    @Id
    @TableId(type = IdType.ASSIGN_ID)
    @ApiModelProperty("编号")
    @JsonFormat(shape = JsonFormat.Shape.STRING)
    @Column(name = "id", columnDefinition = "bigint comment '编号'")
    private Long id;

    /**
     * 用户名
     * 数据脱敏：@Desensitization(type = SensitiveTypeEnum.MOBILE_PHONE)
     * 数据加密： @TableField(typeHandler = AesTypeHandler.class)
     */
    @ApiModelProperty("真实名称")
    @Column(name = "true_name", columnDefinition = "varchar(255) comment '真实名称'")
    @Desensitization(type = SensitiveTypeEnum.CHINESE_NAME)
    @TableField(typeHandler = AesTypeHandler.class)
    private String trueName;

    /**
     * 电话
     * 数据脱敏：@Desensitization(type = SensitiveTypeEnum.MOBILE_PHONE)
     * 数据加密： @TableField(typeHandler = AesTypeHandler.class)
     */
    @ApiModelProperty("电话")
    @Column(name = "phone", columnDefinition = "varchar(255) comment '电话'")
    @Desensitization(type = SensitiveTypeEnum.MOBILE_PHONE)
    @TableField(typeHandler = AesTypeHandler.class)
    private String phone;

    /**
     * 车牌号
     * 数据脱敏：@Desensitization(type = SensitiveTypeEnum.CAR_NUMBER)
     */
    @ApiModelProperty("车牌号")
    @Column(name = "car_number", columnDefinition = "varchar(16) comment '车牌号'")
    @Desensitization(type = SensitiveTypeEnum.CAR_NUMBER)
    private String carNumber;

    /**
     * 身份证
     * 数据脱敏：@Desensitization(type = SensitiveTypeEnum.ID_CARD)
     */
    @ApiModelProperty("身份证")
    @Column(name = "id_card", columnDefinition = "varchar(18) comment '身份证'")
    @Desensitization(type = SensitiveTypeEnum.ID_CARD)
    private String idCard;

    /**
     * 固定电话
     */
    @ApiModelProperty("固定电话")
    @Column(name = "tel", columnDefinition = "varchar(16) comment '固定电话'")
    @Desensitization(type = SensitiveTypeEnum.FIXED_PHONE)
    private String tel;

    /**
     * 邮箱
     */
    @ApiModelProperty("邮箱")
    @Column(name = "email", columnDefinition = "varchar(36) comment '邮箱'")
    @Desensitization(type = SensitiveTypeEnum.EMAIL)
    private String email;

    /**
     * 银行卡号
     */
    @ApiModelProperty("银行卡号")
    @Column(name = "bank_card_number", columnDefinition = "varchar(36) comment '银行卡号'")
    @Desensitization(type = SensitiveTypeEnum.BANK_CARD)
    private String bankCardNumber;

    /**
     * 地址
     */
    @ApiModelProperty("地址")
    @Column(name = "address", columnDefinition = "varchar(255) comment '地址'")
    @Desensitization(type = SensitiveTypeEnum.ADDRESS)
    private String address;
}
